/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pl.pg.misra.Actions;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.List;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.awt.ActionReferences;
import org.openide.awt.ActionRegistration;
import org.openide.loaders.DataObject;
import org.openide.util.NbBundle.Messages;
import pl.pg.misra.AST.AST;
import pl.pg.misra.Interfaces.IRuleChecker;
import pl.pg.misra.Interfaces.ISourceParser;
import pl.pg.misra.Helpers.RuleChecker;
import pl.pg.misra.Helpers.SourceParser;

@ActionID(category = "Build",
id = "pl.pg.misra.ContextASTAnalizer")
@ActionRegistration(displayName = "#CTL_ContextASTAnalizer")
@ActionReferences({
    @ActionReference(path = "Loaders/text/x-c/Actions", position = 0, separatorAfter = 50)
})
@Messages("CTL_ContextASTAnalizer=MISRA-C Compliance")
public final class ContextASTAnalizer extends AbstractAnalizer implements ActionListener {
    ISourceParser parser = new SourceParser();
    IRuleChecker ruleChecker = new RuleChecker();
    
    private final DataObject context;

    public ContextASTAnalizer(DataObject context) {
        this.context = context;
    }

    @Override
    public void actionPerformed(ActionEvent ev) {
        File file = new File(context.getPrimaryFile().getPath());
        
        List<File> astFiles = parser.buildASTFiles(file);
            
        List<AST> result = parser.parseToAST(astFiles);

        List<String> ruleResult = ruleChecker.checkRules(result);

        updateResultTable(ruleResult);
    }
}
